<template>
  <div class="container" ref="mainCon">
    <topTitle :titleText="titleText" :titleExplain="titleExplain"></topTitle>
    <div class="mainCon">
      <el-row class="toolbar searchInputWidth" style="padding-bottom: 0">
        <el-form :inline="true" :model="filterField" ref="searchConditions">
          <el-col :lg="8" :xl="6">
            <el-form-item
              label="所属地区"
              class="row-padding-bottom"
              v-if="loginType == 'JC'"
            >
              <el-cascader
                ref="manageArea"
                v-model="areaId"
                :options="areasOptions"
                @change="getAreaId"
                clearable
                filterable
                :props="{ checkStrictly: true }"
              ></el-cascader>
            </el-form-item>
          </el-col>
          <el-col :lg="8" :xl="6">
            <el-form-item label="行业" class="row-padding-bottom">
              <el-select
                v-model="filterField.industryId"
                filterable
                placeholder="请选择"
                clearable
              >
                <el-option
                  v-for="item in industryOptions"
                  :key="item.code"
                  :label="item.name"
                  :value="item.code"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <template v-if="advanced">
            <el-col :lg="8" :xl="6">
              <el-form-item label="建档日期" class="row-padding-bottom">
                <el-date-picker
                  v-model="filingDate"
                  type="daterange"
                  unlink-panels
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  value-format="yyyy-MM-dd"
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="开工状态" class="row-padding-bottom">
                <el-select
                  v-model="filterField.status"
                  filterable
                  placeholder="请选择"
                  clearable
                >
                  <el-option
                    v-for="item in statusOptions"
                    :key="item.code"
                    :label="item.name"
                    :value="item.code"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="建设方" class="row-padding-bottom">
                <el-input
                  v-model="filterField.pcName"
                  clearable
                  placeholder="请输入"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="施工方" class="row-padding-bottom">
                <el-input
                  v-model="filterField.pbName"
                  clearable
                  placeholder="请输入"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="项目名称" class="row-padding-bottom">
                <el-input
                  v-model="filterField.projectName"
                  placeholder="请输入项目名称"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="评价等级" class="row-padding-bottom">
                <el-select
                  v-model="filterField.gradeLevel"
                  filterable
                  placeholder="请选择"
                  clearable
                >
                  <!-- <el-option v-for="item in levelOptions" :key="item.code" :label="item.name" :value="item.code"></el-option> -->
                  <el-option
                    v-for="item in selectLevel"
                    :key="item.code"
                    :label="item.name"
                    :value="item.code"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </template>
          <el-col :lg="8" :xl="6">
            <el-form-item>
              <!-- <el-button type="primary" icon="icon iconfont iconchazhao1" class="commonBtn" style="margin: 0 0 24px 20px;" v-sdc @click="searchList"></el-button> -->
              <a
                @click="toggleAdvanced"
                style="margin-left: 40px; color: #409eff; cursor: pointer"
                class="btnColor"
              >
                {{ advanced ? '收起' : '展开' }}
                <i
                  :class="advanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
                ></i>
              </a>
              <el-button
                type="primary"
                icon="icon iconfont iconchazhao1"
                @click="searchList"
                class="searchBtn"
              >
                <span>搜索</span>
              </el-button>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div class="spacing"></div>
      <div
        ref="tableBox"
        :class="hiddleToolBar ? 'tableBoxCur tableBox' : 'tableBoxCur'"
      >
        <el-table
          ref="tableBox1"
          :max-height="tableHeight"
          :data="tableList"
          v-loading="loading"
          :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
          highlight-current-row
          stripe
          style="border: 1px solid #dfe6ec"
        >
          <el-table-column prop="projectName" label="项目名称" width="230">
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.projectName"
                :columnName="'projectName'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column
            prop="areaName"
            label="地区"
            align="center"
            :formatter="formatTd"
          ></el-table-column>
          <!-- <el-table-column prop="pcName" label="建设方" align="center" :formatter=formatTd></el-table-column>
                <el-table-column prop="pbName" label="施工方" align="center" :formatter=formatTd></el-table-column>  -->
          <el-table-column
            prop="pcName"
            label="建设方"
            align="left"
            :formatter="formatTd"
            width="230"
          >
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.pcName"
                :columnName="'pcName'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column label="施工方" align="left" width="230">
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.pbName"
                :columnName="'pbName'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column
            prop="score"
            label="评价"
            align="center"
            :formatter="formatTd"
          >
            <template slot-scope="scope">
              <span>{{ scope.row.score }} / {{ scope.row.gradeLevel }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="createTime"
            label="建档日期"
            align="center"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column
            prop="statusDesc"
            label="项目状态"
            align="center"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column label="操作" align="left">
            <template slot-scope="scope">
              <el-link
                type="primary"
                v-hasBtn="'projectEvaluationList:detail'"
                @click="toDetail(scope.$index, scope.row)"
                >查看详情</el-link
              >
              <!-- <span v-else>--</span> -->
            </template>
          </el-table-column>
          <!-- 表格数据为空时，页面显示 -->
          <div slot="empty" v-show="isShow">
            <emptyTable emptyText="暂无相关信息"></emptyTable>
          </div>
        </el-table>
        <!-- filterField为搜索条件 -->
        <!-- getTableList为获取子组件的数据 -->
        <Pagination
          ref="pagination"
          @getList="getTableList"
          :filterField="filterField"
          :requestUrl="requestUrl"
        ></Pagination>
      </div>
    </div>
  </div>
</template>
<script>
import { mapActions, mapState } from 'vuex'
import scrollTable from '@/mixin/scrollTable.js'
export default {
  name: 'projectEvaluationList',
  mixins: [scrollTable],
  data() {
    return {
      // titleText: this.$store.state.activeMenuName,
      titleText: '项目评价',
      titleExplain:
        '针对项目实名制、专户等情况以及项目重大事件，对项目进行评价，频率为每天更新1次',
      levelOptions: [], //评价等级
      statusOptions: [], //状态
      //表格数据
      tableList: [],
      requestUrl: '',
      areaId: '', //区域
      //搜索条件
      filterField: {
        projectId: '',
        projectName: '', //项目名称
        areaId: '', //区域
        status: '', //开工状态
        industryId: '', //行业
        gradeLevel: '', //评价等级
        pcName: '', //建设方
        pbName: '', //施工方
        startDate: '',
        endDate: '',
      },
      isShow: false, //列表加载
      loading: true,
      loginType: '',
      filingDate: [],
      selectLevel: [
        { code: 'A', name: 'A' },
        { code: 'B', name: 'B' },
        { code: 'C', name: 'C' },
        { code: 'D', name: 'D' },
      ],
      advanced: false,
    }
  },
  computed: { ...mapState(['areasOptions', 'industryOptions']) },

  created() {
    this.$store.state.activeMenu = '/home/projectScore/projectEvaluationList'
    this.loginType = localStorage.getItem('loginType')
    if (this.loginType === 'QY' || this.loginType === 'XM') {
      this.requestUrl = 'api-ps/projectscore/expand/listbycompany'
    } else {
      this.requestUrl =
        'api-ps/creditProjectScore/expand/getProjectScoreListByMonitor'
      //获取区域
      this.getAreas({ areaId: this.$store.state.areaInfoArr.areaId })
      if (this.$route.query.type == 'gradeLevelModular') {
        this.areaId = this.$route.query.areaId
        this.filterField.areaId = this.$route.query.areaId
        this.filterField.status = this.$route.query.status
        this.filterField.gradeLevel = this.$route.query.gradeLevel
      }
    }
    if (this.filingDate) {
      this.filterField.startDate = this.filingDate[0]
      this.filterField.endDate = this.filingDate[1]
    } else {
      this.filterField.startDate = ''
      this.filterField.endDate = ''
    }
    // 开工状态
    this.getStatus()

    //获取行业
    this.getIndustry({})
    this.getProject()
    // this.isShowDetail = this.$store.state.buttonLimitsArr.indexOf('projectEvaluationList:detail') > -1;
  },
  watch: {
    $route(to, from) {
      this.getProject()
    },
  },
  mounted() {
    if (this.$route.query.gradeLevel) {
      this.filterField.gradeLevel = this.$route.query.gradeLevel
      this.$refs.pagination.getTableListData()
    }
  },
  methods: {
    ...mapActions(['getAreas', 'getIndustry']),
    toggleAdvanced() {
      this.advanced = !this.advanced
    },
    getProject() {
      if (Object.keys(this.$route.query).length > 0) {
        this.filterField.projectName = this.$route.query.projectName
          ? decodeURI(this.$route.query.projectName)
          : ''
      }
      this.$nextTick(function () {
        this.$refs.pagination.getTableListData()
      })
    },
    // 获取评价等级和开工状态
    getStatus() {
      this.axios({
        method: 'post',
        url: '/api-ps/creditProjectScore/expand/findprowashbytype',
        data: { type: 'PROJECT_STATUS' },
      })
        .then((res) => {
          if (!res.data.hasError) {
            this.statusOptions = res.data.result
          } else {
            this.$message({
              showClose: true,
              duration: 3000,
              message: res.data.errorMsg,
              type: 'error',
            })
          }
        })
        .catch((error) => {
          this.$message({
            showClose: true,
            duration: 3000,
            message: '请求失败',
            type: 'error',
          })
        })
    },
    //获取选中的区域最后一级id
    getAreaId() {
      var areaId = this.areaId[this.areaId.length - 1]
      this.filterField.areaId = areaId
    },
    getTableList(data) {
      this.tableList = data
      this.loading = false
      if (this.tableList.length < 1) {
        this.isShow = true
      }
    },
    // 搜索
    searchList() {
      if (this.filingDate) {
        this.filterField.startDate = this.filingDate[0]
        this.filterField.endDate = this.filingDate[1]
      } else {
        this.filterField.startDate = ''
        this.filterField.endDate = ''
      }
      this.$refs.pagination.getTableListData()
    },
    //跳转详情
    toDetail(index, row) {
      this.$router.push({
        path: '/home/projectScore/evaluationDetail',
        name: 'evaluationDetail',
        query: {
          projectId: row.projectId,
        },
      })
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: '/home/projectScore/projectEvaluationList',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
  },
}
</script>

<style scoped>
.mainCon {
  top: 210px;
}
</style>
